import urllib.request
import random, string
from django.contrib.auth.hashers import make_password, check_password

def sms_send(mobile, code):
    """
    调用鼎信科技， 发送短信验证码
    :param mobile:
    :param code:
    :return:
    """
    host = 'http://dingxin.market.alicloudapi.com'
    path = '/dx/sendSms'
    method = 'POST'
    appcode = 'c706fac7f3d4445696e786c9d912d69d'
    querys = 'mobile={}&param=code%3A{}&tpl_id=TP1711063'.format(mobile, code)
    url = host + path + '?' + querys

    request = urllib.request.Request(url)
    request.method = method
    request.add_header('Authorization', 'APPCODE ' + appcode)
    response = urllib.request.urlopen(request)
    content = response.read()
    if content:
        return content

def create_address(num):
    ran_str = ''.join(random.sample(string.ascii_letters + string.digits, num))
    return ran_str


